<template>
  <div class="body-box">
    <div class="yuan1"></div>
    <div class="yuan2"></div>
    <div class="yuan3"></div>
    <div class="yuan4"></div>

    <div class="box">

      <div class="text-box">
        <h1>欢迎进入JSON编辑系统！！！</h1>
      </div>

      <div class="login-box">
        <h2>用户登录</h2>
        <div class="login">
          <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px"
            class="demo-ruleForm">
            <el-form-item label="账号" prop="username">
              <el-input type="text" v-model="ruleForm.username" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
              <el-input type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
            </el-form-item>

            <el-form-item>
              <el-button style="background: #06f; border: 1px solid #06f;" type="primary"
                @click="submitForm">登录</el-button>
            </el-form-item>
          </el-form>
        </div>

      </div>
    </div>
  </div>
</template>

<script>

  export default {
    name: 'LoginNav',
    data() {
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入账号'));
        } else {
          if (this.ruleForm.passwd !== '') {
            this.$refs.ruleForm.validateField('passwd');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else if (value !== this.ruleForm.password) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {
        ruleForm: {
          username: '',
          password: '',
        },
        rules: {
          username: [
            { validator: validatePass, trigger: 'blur' }
          ],
          password: [
            { validator: validatePass2, trigger: 'blur' }
          ]
        }
      };
    },

    mounted() {

    },

    methods: {
      submitForm() {
        console.log(this.ruleForm.username);
        console.log(this.ruleForm.password);
        if (this.ruleForm.username === "root" && this.ruleForm.password === "123456") {
          this.$message({
            message: '恭喜你，成功管理员登陆成功！',
            type: 'success'
          });
          this.$router.push("/index")
        } else {
          this.$message.error('警告哦，密码错误或者没有账号！！');
        }
      },
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .body-box {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    /* border: 1px solid red; */
  }

  .body-box .box {
    max-width: 1000px;
    height: 500px;
    display: flex;
    /* border: 1px solid red; */
    background: #fff;
    border-radius: 10px;
    z-index: 1;
  }

  .body-box .box .text-box {
    width: 500px;
    display: flex;
    justify-content: center;
    align-items: center;
    /* border: 1px solid blue; */
  }

  .body-box .box .login-box {
    width: 500px;
    padding: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    position: relative;
    /* border: 1px solid green; */

  }

  .body-box .box .login-box::after {
    width: 3px;
    border-radius: 10px;
    height: 350px;
    content: "";
    position: absolute;
    background: #dadada;
    left: 0;
    top: 11%;
  }

  .body-box .box .login-box h2 {
    width: 500px;
    text-align: center;
    /* border: 1px solid red; */
  }

  .body-box .box .login-box .login {
    margin-top: 50px;
  }

  .body-box .yuan1,
  .yuan2,
  .yuan3,
  .yuan4 {
    /* border: 1px solid red; */
  }

  .body-box .yuan1 {
    width: 800px;
    height: 800px;
    background: #06f;
    border-radius: 50%;
    position: absolute;
    left: -250px;
    top: -250px;
    z-index: 0;
  }

  .body-box .yuan2 {
    width: 400px;
    height: 400px;
    background: #06f;
    border-radius: 50%;
    position: absolute;
    left: 350px;
    top: -200px;
    z-index: 0;
  }

  .body-box .yuan3 {
    width: 600px;
    height: 600px;
    background: #06f;
    border-radius: 50%;
    position: absolute;
    left: -150px;
    bottom: -350px;
    z-index: 0;
  }

  .body-box .yuan4 {
    width: 700px;
    height: 700px;
    background: #06f;
    border-radius: 50%;
    position: absolute;
    right: -250px;
    top: -300px;
    z-index: 0;
  }
</style>